<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" href="https://cache.amap.com/lbs/static/main1119.css"/>
    <title>Baidu Map </title>
    <style type="text/css">
        html{height:100%}
        body{height:100%;margin:0px;padding:0px}
        #container{height:100%}
    </style>
</head>
<body>
<div id="container" style="width:100%; text-align: center;"></div>
<div id="myPageTop">
    <table>
        <tr>
            <td>
                <label>请输入关键字：</label>
            </td>
        </tr>
        <tr>
            <td>
                <input id="tipinput"/>
            </td>
        </tr>
        <tr>
            <td>
                <button id = "go" class="layui-btn icon-btn" onclick="closeThis()"><i class="layui-icon">&#xe654;</i>确认</button>
            </td>
            <td>

            </td>
        </tr>
    </table>
</div>
</body>
<script src="https://webapi.amap.com/maps?v=1.4.15&key=4981ea090fb3a481d31ebf73fa451d3b&plugin=AMap.DistrictSearch,AMap.Geocoder,AMap.DistrictLayer,AMap.AutoComplete,AMap.PlaceSearch">
</script>
<!-- 引入 layui.css -->
<link rel="stylesheet" href="//unpkg.com/layui@2.6.8/dist/css/layui.css">

<!-- 引入 layui.js -->
<script src="//unpkg.com/layui@2.6.8/dist/layui.js"></script>

<script>
    //地图加载
    var map = new AMap.Map("container", {
        resizeEnable: true
    });
    //输入提示
    var autoOptions = {
        input: "tipinput"
    };


    AMap.plugin(['AMap.PlaceSearch','AMap.AutoComplete'], function(){
        var auto = new AMap.AutoComplete(autoOptions);
        var placeSearch = new AMap.PlaceSearch({
            map: map
        });  //构造地点查询类
        auto.on("select", select);//注册监听，当选中某条记录时会触发
        function select(e) {
            placeSearch.setCity(e.poi.adcode);
            placeSearch.search(e.poi.name);  //关键字查询查询
        }
    });
    var marker = new AMap.Marker({
        position: map.getCenter(),
        offset: new AMap.Pixel(-10, -10),
        // 设置是否可以拖拽
        draggable: false,
        cursor: 'move',
        // 设置拖拽效果
        raiseOnDrag: true
    });
    marker.setMap(map);
    var lngVal,latVal = "";
    var clickHandler = function(e) {
        marker.setMap(null);
        marker = new AMap.Marker({
            position: e.lnglat,
            offset: new AMap.Pixel(-10, -10),
            // 设置是否可以拖拽
            draggable: false,
            cursor: 'move',
            // 设置拖拽效果
            raiseOnDrag: true
        });
        marker.setMap(map);
        lngVal = e.lnglat.lng;
        latVal = e.lnglat.lat;
        console.log(e.lnglat.lng+";"+e.lnglat.lat)
    };

    map.on('click', clickHandler);

    //点击确定向子页面传参并关闭窗口
    function closeThis(){
        parent.getValue(1,latVal,lngVal);
        if(latVal==undefined||latVal==""||lngVal==undefined||lngVal==""){
            alert("请选择地址")
        }else {
            var index = parent.layer.getFrameIndex(window.name); //获取当前窗口的name
            parent.layer.close(index);//关闭窗口
        }
        /* alert(lngVal+";"+latVal);*/
    }
</script>
</html>